package com.ruoyi.contract.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.contract.domain.Cproject;
import com.ruoyi.contract.model.Query1;
import com.ruoyi.contract.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/contract")
public class ContractController extends BaseController {

    @Autowired
    ContractService service;

    @PostMapping("add1")
    public AjaxResult submitForm1(@RequestBody Cproject cproject){
        if (service.checkContractCode(cproject.getContractCode())==0){
            Long id = service.add1(cproject);
            return success(id);
        }else {
            return  error("合同编号重复");
        }
    }
    @GetMapping("check/name")
    public AjaxResult checkName(String name){
        int i = service.checkContractCode(name);
        return success(i);
    }
    @GetMapping("list")
    public TableDataInfo list(Query1 query){
        startPage();
        List<Cproject> list = service.list(query);
        return getDataTable(list);
    }
    @GetMapping
    public AjaxResult getById(String id){
        long l = Long.parseLong(id);
        Cproject one = service.getOne(l);
        return success(one);
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Cproject cproject){
        service.update(cproject);
        return success(cproject.getProjectId());
    }

    @GetMapping("/remove")
    public AjaxResult remove(Long id){
        Integer i = service.removeOne(id);
        return success();
    }
}
